package _Pan3D.display3D
{
	
	import _Pan3D.display3D.interfaces.IDisplay3D;
	import _Pan3D.display3D.interfaces.IDisplay3DContainer;
	import _Pan3D.display3D.interfaces.IDisplay3DMovie;
	
	import flash.display3D.Program3D;
	import flash.geom.Matrix3D;
	
	/**
	 * @author MSN:liuyan3757@163.com  QQ: 421537900
	 */
	public class Display3DContainer extends Display3D implements IDisplay3DContainer
	{
		protected var _childrenList:Vector.<IDisplay3D>;
		public function Display3DContainer()
		{
			_childrenList = new Vector.<IDisplay3D>;
		}
		
		public function play(action:String):void{
			for(var i:int;i<_childrenList.length;i++){
				if(_childrenList[i] is IDisplay3DMovie){
					IDisplay3DMovie(_childrenList[i]).play(action);
				}
			}
		}
		
		public function update():void
		{
			for(var i:int;i<_childrenList.length;i++){
				_childrenList[i].update();
			}
			
		}
		public function updataAndScanning():void
		{
			
		}
		

		
		public function setMatrix(modelMatrix:Matrix3D):void
		{
			for(var i:int;i<_childrenList.length;i++){
				_childrenList[i].setMatrix(modelMatrix);
			}
		}
		
		public function addChild(display3D:IDisplay3D):void{
			_childrenList.push(display3D);
			display3D.parent = this;
		}
		
		public function removeChild(display3D:IDisplay3D):void{
			var index:int = _childrenList.indexOf(display3D);
			if(index == -1){
				return;
			}
			_childrenList.splice(index,1);
			display3D.parent = null;
		}
		
		public function removeAllChildren():void{
			_childrenList = new Vector.<IDisplay3D>;
		}
		
		override public function updateMatrix():void{
			this.x = this.parent.x + this.x;
			this.y = this.parent.y + this.y;
			this.z = this.parent.z + this.z;
		}
		
		override public function updataPos():void{
			if(this.parent){
				this.absoluteX = this.x + this.parent.absoluteX;
				this.absoluteY = this.y + this.parent.absoluteY;
				this.absoluteZ = this.z + this.parent.absoluteZ;
			}else{
				this.absoluteX = this.x;
				this.absoluteY = this.y;
				this.absoluteZ = this.z;
			}
			for(var i:int;i<_childrenList.length;i++){
				_childrenList[i].updataPos();
				_childrenList[i].update();
			}
		}
		
		override public function setProgram3D(value:Program3D):void{
			program = value;
			for(var i:int;i<_childrenList.length;i++){
				_childrenList[i].setProgram3D(program);
			}
		}
		
		
	}
}